package org.soarsky.wealthchengdu.module.focus;

import org.soarsky.wealthchengdu.R;
import org.soarsky.wealthchengdu.appliction.MyAppliction;
import org.soarsky.wealthchengdu.entity.NewsContentData;
import org.soarsky.wealthchengdu.util.Config;
import org.soarsky.wealthchengdu.view.ALLSendDialog;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 、 滑动控件
 * 
 * @author huang
 * 
 */
public class FocusDelitScroll extends Activity {

	private WebView showWV;

	private TextView focus_tv_name;
	private TextView tv_one;
	private TextView focus_off;
	private TextView focus_day;
	
    private TextView cd_tv_zan;
    private TextView cd_tv_chat;
    private TextView cd_tv_collectss;
    private TextView cd_tv_share;
	static NewsContentData newscontentdata;

	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.activity_focus);

		showWV = (WebView) findViewById(R.id.focus_webview);
		focus_tv_name = (TextView)findViewById(R.id.focus_tv_name);
		focus_day = (TextView)findViewById(R.id.focus_day);
		focus_off = (TextView)findViewById(R.id.focus_off);
		tv_one = (TextView)findViewById(R.id.tv_one);
		cd_tv_zan = (TextView)findViewById(R.id.cd_tv_zan);
		cd_tv_chat = (TextView)findViewById(R.id.cd_tv_chat);
		cd_tv_collectss = (TextView)findViewById(R.id.cd_tv_collectss);
		cd_tv_share = (TextView)findViewById(R.id.cd_tv_share);
		showWV.getSettings().setJavaScriptEnabled(true);
		showWV.requestFocus();

		setwebview();
	}

	static void setID(NewsContentData url) {
		FocusDelitScroll.newscontentdata = url;
	}

	public void setwebview() {
		String ss = "";
		if (FocusDelitScroll.newscontentdata != null) {
			if (MyAppliction.mCn == 0) {

				if (MyAppliction.mcateID.equals("104")) {
					ss = MyAppliction.video;
				} else {
					ss = MyAppliction.htmlhead;
				}
				showWV.loadDataWithBaseURL(null, ss
						+ FocusDelitScroll.newscontentdata.getContent()
						+ MyAppliction.htmlbottom, "text/html", "utf-8", null);
				showWV.setWebChromeClient(new MyWebChromeClient());
				focus_tv_name.setText(FocusDelitScroll.newscontentdata.getTitle());
				focus_day.setText(FocusDelitScroll.newscontentdata.getAddTime());
				focus_off.setText(FocusDelitScroll.newscontentdata.getAgenda());
				// webview.setWebViewClient(new WebViewClient()
				// {
				// @Override
				// public void onPageFinished(WebView view,String url)
				// {
				// ALLSendDialog.dimssdialog();
				// }
				// });
			} else {
				showWV.loadDataWithBaseURL(null, ss
						+ FocusDelitScroll.newscontentdata.getContentEn()
						+ MyAppliction.htmlbottom, "text/html", "utf-8", null);
				showWV.setWebChromeClient(new MyWebChromeClient());
				focus_tv_name.setText(FocusDelitScroll.newscontentdata.getTitleEn());
				focus_day.setText(FocusDelitScroll.newscontentdata.getAddTime());
				focus_off.setText(FocusDelitScroll.newscontentdata.getAgendaEn());
				// webview.setWebViewClient(new WebViewClient()
				// {
				// @Override
				// public void onPageFinished(WebView view,String url)
				// {
				// ALLSendDialog.dimssdialog();
				// }
				// });
			}
		} else {
			Toast.makeText(this,
					Config.changeLanguage(MyAppliction.mChoose).getNodata(),
					Toast.LENGTH_LONG).show();
		}
		cd_tv_share.setText(FocusDelitScroll.newscontentdata.getShareNum());
		cd_tv_zan.setText(FocusDelitScroll.newscontentdata.getAdmireNum());
		cd_tv_chat.setText(FocusDelitScroll.newscontentdata.getRemarkNum());
		cd_tv_collectss.setText(FocusDelitScroll.newscontentdata.getCollectNum());
		
	}

	class MyWebChromeClient extends WebChromeClient {
		@Override
		public void onProgressChanged(WebView view, int newProgress) {
			// TODO Auto-generated method stub
			// 查看加载进度
			Log.e("the load", "~~~~~~~~progress:" + newProgress); // //////////
			// 加载完毕
			if (newProgress == 100) {
				ALLSendDialog.dimssdialog();
			}
			super.onProgressChanged(view, newProgress);
		}

	}

}
